/*
 ============================================================================
 Name		: ResponseSavePoints.cpp
 Author	  : 
 Version	 : 1.0
 Copyright   :
 Description : CResponseSavePoints implementation
 ============================================================================
 */

#include "ResponseSavePoints.h"
#include "ResponseDefinses.h"
#include "ProjectsDefines.h"
#include "ResponseSavePointsData.h"
#include "BetterUserHBufC.h"

CResponseSavePoints::CResponseSavePoints()
{
    // No implementation required
}

CResponseSavePoints::~CResponseSavePoints()
{
    SAFE_DELETE( _data );
}

CResponseSavePoints* CResponseSavePoints::NewLC()
{
    CResponseSavePoints* self = new ( ELeave ) CResponseSavePoints( );
    CleanupStack::PushL( self );
    self->ConstructL( );
    return self;
}

CResponseSavePoints* CResponseSavePoints::NewL()
{
    CResponseSavePoints* self = CResponseSavePoints::NewLC( );
    CleanupStack::Pop( ); // self;
    return self;
}

void CResponseSavePoints::ConstructL()
{
    _data = CResponseSavePointsData::NewL( );
}

void CResponseSavePoints::LoadValidResponseFromXmlNode(CElement* elementResponse)
{
    _ASSERT_LOG( elementResponse != NULL );

    if( !elementResponse )
    {
        return;
    }

    CElement* elementResult = elementResponse->GetElement( kResponseResultNode );

    _ASSERT_LOG( elementResult != NULL );
    if( !elementResult )
    {
        return;
    }
    /*
     * <order_id>string</order_id>
     * <num>int</num>
     * <unit>string</unit>
     * <time>string</time>
     * <bank_url>string</bank_url>
     */
    _LIT( kResponseOrderIdNode, "order_id" );
    _LIT( kResponseNumNode, "num");
    _LIT( kResponseUnitNode, "unit" );
    _LIT( kResponseTimeNode, "time");
    _LIT( kResponseBankUrlNode, "bank_url");

    _data->_order_id = BetterUtility::GetElementText( elementResult->GetElement( kResponseOrderIdNode ) );
    _data->_number = BetterUtility::GetElementTextAsInt( elementResult->GetElement( kResponseNumNode ) );
    _data->_unit = BetterUtility::GetElementText( elementResult->GetElement( kResponseUnitNode ) );
    _data->_time = BetterUtility::GetElementText( elementResult->GetElement( kResponseTimeNode ) );
    _data->_bank_url = BetterUtility::GetElementText( elementResult->GetElement( kResponseBankUrlNode ) );

}
